<?php

if(!$_SESSION) session_start();
// Connect to the database
////////////////////////////////////////////////////////

require_once("../scripts/config.php");

// Load Functions
////////////////////////////////////////////////////////

require_once("../scripts/functions.php");


// Update Project
////////////////////////////////////////////////////////

if(isset($_POST) && ($_POST['set_post']==1)){

	$set_active = "0";

	if($_POST['set_active']=="yes") $set_active = 1;

	$sql = sprintf("UPDATE tblprojects SET project_label = %s, set_active = %s, UserID=%s WHERE ProjectID = %s",
					GetSQLValueString($_POST['project_label'], "text"),
					GetSQLValueString($set_active, "int"),
					GetSQLValueString($_SESSION['UserID'], "int"),
                                        GetSQLValueString($_POST['ProjectID'], "int"));

	sqlMod($sql, $db);

       	exit("Project Updated Successfully!");

}

// Load Project
////////////////////////////////////////////////////////

$sql = "SELECT * FROM tblprojects WHERE ProjectID = ".$_GET['ID'];

$project = sqlLoad($sql, $db);

?>
<form id="formUP" name="formUP" method="POST" action="/forms/project_edit.php">
  <p>
    <label>
      <input type="text" name="project_label" id="project_label" value="<?php echo $project[0]['project_label'];?>" />
    </label>
    Project Name
    <input name="set_post" type="hidden" id="set_post" value="1" />
    <input name="ProjectID" type="hidden" id="ProjectID" value="<?php echo $project[0]['ProjectID'];?>" />
  </p>
  <p>
    <label>
      <input type="checkbox" name="set_active" id="set_active" value="yes" <?php if($project[0]['set_active']==1) echo "checked";?> />
      This project is active and ready for tasks</label>
  </p>
</form>